package com.cmcc.aregister.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.cmcc.aregister.cs.database.DatabaseAdapter;
import com.cmcc.aregister.cs.model.MemberModel;
import com.cmcc.aregister.cs.model.User;

public class OrderAdapterMsg extends BaseAdapter {
	private Context context;
	private int[] title = { R.string.msg_name,R.string.msg_relation, R.string.msg_sex,
			 R.string.msg_birth,R.string.msg_mobile, R.string.msg_card,R.string.msg_social_num,
			};
//	private int[] title = { R.string.msg_name, R.string.msg_sex,
//			R.string.msg_mobile,
//	};
	private String[] contentStr = new String[7];
	private User user;
	private DatabaseAdapter mDatabaseAdapter;
	public OrderAdapterMsg(Context context,MemberModel member) {
		this.context = context;
		/*mDatabaseAdapter = new DatabaseAdapter(context);
		user = new User();
		mDatabaseAdapter.open_user();
		Cursor c = mDatabaseAdapter.fetchAllUserData();
		if (c != null) {
			c.moveToFirst();
			if (c.getCount() > 0) {
				try{
					user.name = UniqueKey.decodeStr(c.getString(c.getColumnIndex("username")));
					user.mobile = UniqueKey.decodeStr(c.getString(c.getColumnIndex("mobile")));
					user.birth = UniqueKey.decodeStr(c.getString(c.getColumnIndex("birth")));
					int sexId = Integer.valueOf(UniqueKey.decodeStr(c.getString(c.getColumnIndex("sex"))));
					if (sexId == 0) {
						user.sex = context.getString(R.string.man);
					} else {
						user.sex = context.getString(R.string.woman);
					}
					user.card = UniqueKey.decodeStr(c.getString(c.getColumnIndex("card")));
					user.social_card = UniqueKey.decodeStr(c.getString(c.getColumnIndex("social_card")));
					user.login_date = UniqueKey.decodeStr(c.getString(c.getColumnIndex("login_date")));
				}catch (Exception e) {
					// TODO: handle exception
				}
			}
		}
		c.close();
		mDatabaseAdapter.close_user();*/
		
		contentStr[0] = member.truename;
		contentStr[1] = ConfigUtilHelper.getRelationText(context,member.relation,member.sex);
		contentStr[2] = member.sex == 0 ? "男" : "女";
		contentStr[3] = member.birth;
		contentStr[4] = member.phone;
		contentStr[5] = member.card;
		contentStr[6] = member.social_card;
//		contentStr[0] = user.name;
//		contentStr[1] = user.sex;
//		contentStr[2] = user.mobile;
	}



	static class ViewHolder {
		TextView title;
		TextView content;
		ImageView tag;
	}

	@Override
	public int getCount() {
		return title.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.a_text_text_image, null);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.content = (TextView) convertView.findViewById(R.id.content);
			holder.tag = (ImageView) convertView.findViewById(R.id.tag);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.title.setText(title[position]);
//		convertView.setBackgroundResource(R.drawable.expandable_center);
		holder.content.setVisibility(View.VISIBLE);
		holder.tag.setVisibility(View.GONE);
		holder.title.setTextColor(context.getResources().getColor(
				R.color.black));
		
		holder.content.setText(contentStr[position]);
		return convertView;
	}
}
